﻿using System;

namespace WeatherInformer
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var weather = new WeatherInfo();
            weather.UpdateConditions();
            Console.Write(GetConditions(weather.Conditions));
            while (Console.ReadKey().Key != ConsoleKey.Escape)
            {
                weather.UpdateConditions();
                Console.Write(GetConditions(weather.Conditions));
            }
        }

        private static string GetConditions(WeatherConditions conditions)
        {
            var result = String.Format("{0}\n{1}\nt = {2}C, p = {3}Pa, h = {4}%\n{5}\n{6}\n", 
                conditions.City, 
                conditions.Time, 
                conditions.Temperature, 
                conditions.Pressure, 
                conditions.Humidity, 
                conditions.Date,
                (String.IsNullOrEmpty(conditions.Error) ? "" : "Error: " + conditions.Error)
                );
            return result;
        }
    }
}
